﻿/****************************************************************************
**  @copyright  TinKinG
**  @contract   lsnbing@126.com
**
**  @author TinKinG
**  @date   2020-3-12
**
**
*****************************************************************************/

#ifndef PERSPECTIVEVIEW_H
#define PERSPECTIVEVIEW_H

#include <QWidget>
#include <QImage>

#include <opencv.hpp>

using namespace cv;

class PerspectiveView : public QWidget
{
    Q_OBJECT
public:
    explicit PerspectiveView(QWidget *parent = nullptr);

    void paintEvent(QPaintEvent *event);
    void mouseMoveEvent(QMouseEvent *ev);

    cv::Mat getMatFromImage(const QImage &img);
    QImage getImageFromMat(const cv::Mat &mat);

    cv::Mat PerspectiveTrans(Mat src, Point2f* scrPoints, Point2f* dstPoints);

private:
    QRectF getRect(const QPointF &p);
public:
    void setMainImg(const QImage &img);
    void setTopImg(const QImage &img);

    QImage getImage() const;

private:
    int m_radius;
    QPointF p1,p2,p3,p4;

    QImage m_bkgImg;
    QImage m_mainImg;
    QImage m_topImg;

    cv::Mat m_srcMat;
    cv::Mat m_dstMat;
};

#endif // PERSPECTIVEVIEW_H
